package com.company;

import java.util.Scanner;

/**
 * @description:
 * @author: Lenovo
 * @date: Crcoted in 2020/05/25 20:57
 * @version:${VERSION}
 * @modified By:
 */
public class Sense{

    Person person=new Person();

    Monsters tiger = new Monsters();
    Monsters lion = new Monsters();
    Monsters wolf = new Monsters();

   RoomSet roomSet = new RoomSet();
MonstersSet monstersSet=new MonstersSet();


    Ui ui = new Ui();

    public void initSense () {
        initRooms();
        initPerson(roomSet.searchRoomById("1"));
        initMonster();

    }


    public void initMonster() {
        tiger.setId("tiger");
        tiger.setDescription("老虎");
        tiger.setHp(250);
        tiger.setCurrentWeapon(new WGun("g1", "机关枪", -50));
        lion.setId("lion");
        lion.setDescription("狮子");
        lion.setHp(350);
        lion.setCurrentWeapon(new WGun("g2", "机关枪", -20));
        wolf.setId("wolf");
        wolf.setDescription("狼");
        wolf.setHp(300);
        wolf.setCurrentWeapon(new WGun("g3", "机关枪", -30));
        monstersSet.getBadMonster().add(tiger);
        monstersSet.getBadMonster().add(lion);
        monstersSet.getBadMonster().add(wolf);
    }

    public void  initPerson(Room room){
        person.setId("girl");
        person.setDescription("霍秀");
        person.setHp(500);
        person.setCurrentWeapon(new WGun("g","手枪",-40));
        person.setCurrentWeapon(new Wliquid("liquid","生命药水",+20));
        person.setCurrentRoom(room);

    }

    private void initRooms () {
        Room outside=new Room("1", "庭院");
        Room palace=new Room("2", "宫殿");
        Room magicroom =new Room("3", "魔法屋");
        Room revolvingrestayrant =new Room("4", "旋转餐厅");
        Room bedroom=new Room("5", "卧室");

        outside.addReachableRoom("2", palace);
        outside.addReachableRoom("3",magicroom );
        outside.addReachableRoom("4", revolvingrestayrant);

        palace.addReachableRoom("1",outside);

        magicroom.addReachableRoom("1", outside);

        revolvingrestayrant.addReachableRoom("1", outside);
        revolvingrestayrant.addReachableRoom("5", bedroom);

        bedroom.addReachableRoom("4", revolvingrestayrant);

        roomSet.addRoom(outside);
        roomSet.addRoom(palace);
        roomSet.addRoom(magicroom);
        roomSet.addRoom(revolvingrestayrant);
        roomSet.addRoom(bedroom);
    }

    public void play() {
        ui.displayStaus(this);
        Scanner in=new Scanner(System.in);
        while (true) {
            //用户输入命令
            String command = in.nextLine();
            //分割命令行各个单元
            String[] words = command.split(" ");
            //根据命令，做相应动作
            if (words[0].equals("help")) {
                ui.displayHelpMsg();
            } else if (words[0].equals("bye")) {
                ui.displayBye();
            } else if (words[0].equals("返回")) {
                Ui.printWelcome(getPerson());
                break;
            }else if(words[0].equals("拿取生命药水")) {
                person.useArticle(person.getCurrentWeapon(),this.getPerson());
            } else if (words[0].equals("chop")) {
                this.getPerson().useArticle(getPerson().getCurrentWeapon(), this.getMonstersSet().get(words[1]));
                ui.displayDamageMsg(this.person, this.getMonstersSet().get(words[1]));
                ui.displayDamageMsg(this.getMonstersSet().get(words[1]), this.person);
                if (words[1].equals("lion")) {
                    lion.useArticle(lion.getCurrentWeapon(), this.getPerson());
                }
                if (words[1].equals("tiger")) {
                    tiger.useArticle(tiger.getCurrentWeapon(), this.getPerson());
                }
                if (words[1].equals("wolf")) {
                    wolf.useArticle(wolf.getCurrentWeapon(), this.getPerson());
                }
            }else {
                ui.displayErrorCmdMsg();
            }

               ui.displayStaus(this);
                ui.displayHelpMsg();
            }
            System.out.println();
            ui.displayStaus(this);
        }



    public MonstersSet getMonstersSet() {
        return monstersSet;
    }

    public void setMonstersSet(MonstersSet monstersSet) {
        this.monstersSet = monstersSet;
    }

    public Person getPerson () {
        return person;
    }

    public void setPerson (Person person) {
        this.person=person;
    }

    public RoomSet getRoomSet() {
        return roomSet;
    }

    public void setRoomSet(RoomSet roomSet) {
        this.roomSet = roomSet;
    }



}


